package com.yumingjiang.weichatgtp.common.thread;

import com.yumingjiang.commontool.util.LoggerUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * [线程抽象类]
 *
 * @author : [Administrator]
 * @version : [v1.0]
 * @createTime : [2023/3/11 19:21]
 */
public abstract class AbstractRunnable implements Runnable {
    private final Logger LOGGER = LoggerFactory.getLogger(AbstractRunnable.class);
    private String taskName;

    protected abstract void runDo();

    public AbstractRunnable(String taskName) {
        this.taskName = taskName;
    }

    @Override
    public void run() {
        try {
            LoggerUtil.info(LOGGER,"Asynchronous thread is executing ：[" + taskName + "] task.");
            runDo();
            LoggerUtil.info(LOGGER,"The asynchronous thread has completed the [" + taskName + "] task.");
        } catch (Exception e) {
            LoggerUtil.error(LOGGER,e,"Asynchronous thread failed to execute  [" + taskName + "]  task");
        }
    }
}
